import os,shutil,sys
from PIL import Image

def adjust_image_size(input_path, output_path):
    # 打开图像
    with Image.open(input_path) as img:
        width, height = img.size
        new_width=int(24*118.1)
        new_height = int(new_width * height / width)
        if new_height>int(28*118.1):
            new_height=int(28*118.1)
            new_width=int(new_height * width / height)
        img_resized = img.resize((new_width, new_height))
        img_resized.save(output_path)
        print(f"图片已保存为 {output_path}")



dir="D:/Desk/TEMU-批量上款/1-内容分组/"
folders=os.listdir(dir)
for folder in folders:
    model=folder.split("_")[0]
    pattern=folder.replace(model+'_',"")
    if 'TK' in pattern:
        path="Y:/pic/pattern/"+pattern+'.png'
    else:
        path="Y:/pic/draw/"+pattern+'.png'
    if not os.path.exists(path):
        print("文件不存在！")
    else:
        path_new=dir+folder+"/pic&"+pattern+".png"
        adjust_image_size(path,path_new)